﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BuildAdd.aspx.cs" Inherits="ZLDC.Estate.TM.BuildAdd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>栋阁新增</title>
    <base target="_self" />
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../js/jquery/style/jquery.hiAlerts.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" action="../Handler/HandlerIndex.ashx?act=build_save" enctype="multipart/form-data"
    method="post">
    <div style="height: 4px;">
    </div>
    <table width="550px" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
        <tr>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                楼盘名称：
            </td>
            <td width="30%" bgcolor="#FFFFFF" style="padding-left: 10px;">
                <asp:Label ID="lbEstateName" runat="server" Text=""></asp:Label>
            </td>
        </tr>
        <tr>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                上级名称：
            </td>
            <td width="30%" bgcolor="#FFFFFF" style="padding-left: 10px;">
                <select id="sBuild" name="sBuild" style="width: 50%;" runat="server">
                </select><font color="red">*</font>
            </td>
        </tr>
        <tr>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                新增方式：
            </td>
            <td width="30%" bgcolor="#FFFFFF" style="padding-left: 10px;">
                <input id="radioType1" name="radioType" type="radio" checked onclick="changeType(1)" />单一新增
                <input id="radioType2" name="radioType" type="radio" onclick="changeType(2)" />批量新增
                <input id="hTypeId" name="hTypeId" type="hidden" /><font color="red">*</font>
            </td>
        </tr>
        <tr>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                小区单元：
            </td>
            <td width="30%" bgcolor="#FFFFFF" style="padding-left: 10px;">
                <div id="divType1" style="display: block;">
                    栋阁名：
                    <input id="iName" name="iName" type="text" value="" class="textdocdown" style="width: 30%" /><font color="red">*</font>
                </div>
                <div id="divType2" style="display: none;">
                    栋阁名： 前缀<input id="iNameFirst" name="iNameFirst" type="text" value="" class="textdocdown"
                        style="width: 10%" />&nbsp;&nbsp; 中间<input id="iName1" name="iName1" type="text"
                            value="" class="textdocdown" style="width: 5%" />~
                    <input id="iName2" name="iName2" type="text" value="" class="textdocdown" style="width: 5%" />&nbsp;&nbsp;
                    后缀<input id="iNameEnd" name="iNameEnd" type="text" value="" class="textdocdown" style="width: 10%" />
                </div>
                <%--单 位：
                <select id="sUnit" name="sUnit" style="width: 60px;" runat="server" >
                    <option selected value="手填">手填</option>
                    <option value="栋">栋</option>
                    <option value="号">号</option>
                    <option value="座">座</option>
                    <option value="幢">幢</option>
                    <option value="号楼">号楼</option>
                    <option value="单元">单元</option>
                    <option value="梯">梯</option>
                </select>--%>
            </td>
        </tr>
        <tr>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                总层数：
            </td>
            <td width="30%" bgcolor="#FFFFFF" style="padding-left: 10px;">
                <input id="iFloorTotal" name="iFloorTotal" type="text" value="" class="textdocdown"
                    style="width: 10%" /><font color="red">*</font>
                &nbsp;类型：
                <select id="sType" name="sType" runat="server">
                    <%--<option>全部</option>
                    <option>裙楼</option>
                    <option>别墅</option>
                    <option>小高层</option>
                    <option>多层</option>
                    <option>高层</option>--%>
                </select>
                &nbsp;用途：
                <select id="sUsage" name="sUsage" runat="server">
                    <%--<option>住宅</option>
                    <option>商铺</option>
                    <option>厂房</option>--%>
                </select>
            </td>
        </tr>
        <tr>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                备注：
            </td>
            <td width="30%" bgcolor="#FFFFFF" style="padding-left: 10px;">
                <textarea id="taRemark" name="taRemark" style="width: 80%; height: 70px"></textarea>
            </td>
        </tr>
        <tr>
            <td width="10%" align="right" bgcolor="#F7F7F7">
                别名：
            </td>
            <td width="30%" bgcolor="#FFFFFF" style="padding-left: 10px;">
                <input id="iOtherName" name="iOtherName" type="text" value="" class="textdocdown"
                    style="width: 30%" />
            </td>
        </tr>
    </table>
    <div style="width: 550px; padding-top: 15px; cursor: pointer; text-align: center;">
        <input id="btnOk" class="button_bak2" type="button" value="保存" onclick="submitOK(0)" />
        <input id="btnSave"  class="button_bak2" type="button" value="保存并新增房号"   onclick="return submitOK(1);" />   

    </div>
    <br />
    <input id="hID" name="hID" type="hidden" runat="server" />
    <input id="hEID" name="hEID" type="hidden" runat="server" />
    <input id="ActionType" name="ActionType" type="hidden" />
    <input id="typeid" name="typeid" type="hidden" />

    </form>

    <script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="../js/jquery/jquery.hiAlerts-min.js" type="text/javascript"></script>

    <script src="../js/LexunJS.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            var id = LexunJS.GetQueryString("id");
            var typeid = LexunJS.GetQueryString("typeid");
            document.getElementById("typeid").value = typeid;

            if (typeid == "1" || typeid=="2") {//如果Typeid等于1时，显示保存并新增房号
                document.getElementById("btnSave").style.display = "";
            } else {
                document.getElementById("btnSave").style.display = "none";
            }
            // 修改
            if (id > 0)
                showDetail(id);
        });

        // 查询详细
        function showDetail(id) {
            $.ajax({
                type: 'POST',
                url: '../Handler/HandlerIndex.ashx',
                data: 'act=build_detail&id=' + id,
                timeout: '10000',
                error: function() {
                    alert("查询详情失败！");
                }, success: function(json) {
                    showDetailCallBack(json);
                }
            });
        }
        function showDetailCallBack(response) {
            var json = eval("(" + response + ")");
            var record = json.record;

            if (record == null || record.length == 0)
                return;

            var recordLength = record.length;
            for (var i = 0; i < recordLength; i++) {
                $("#hID").val(record[i].id);
                $("#hEID").val(record[i].eid);
                $("#sBuild").val(record[i].parentid);
                $("#iName").val(record[i].name);
                $("#iOtherName").val(record[i].othername);
                $("#iFloorTotal").val(record[i].floortotal);
                $("#sUsage").val(record[i].usage);
                $("#taRemark").val(record[i].remark);
            }
        }

        // 切换新增模式 1单一 2批量
        function changeType(typeid) {
            if (typeid == 1) {
                $("#divType1").show();
                $("#divType2").hide();
                $("#hTypeId").val("1");
            } else {
                $("#divType1").hide();
                $("#divType2").show();
                $("#hTypeId").val("2");
            }
        }

        // 提交前验证
        function submitOK(obj) {
            // 新增方式判断
            document.getElementById("ActionType").value = obj; ///操作类型，0-保存楼盘信息，1保存并新增栋阁
            var reg = /^[A-Za-z]+$/;///验证是否是字母
            if (document.getElementById("radioType1").checked) {
                var name = document.getElementById("iName").value;
                if (name == "") {
                    alert("栋阁名称不能为空！");
                    document.getElementById("iName").focus();
                    return false;
                }
            } else {
                var name1 = document.getElementById("iName1").value;
                if (name1 == "") {
                    alert("批量新增栋阁名称中间不能为空！");
                    document.getElementById("iName1").focus();
                    return false;
                } else {
                if (!LexunJS.isValidPositiveInteger(name1) && !reg.test(name1)) {
                        alert("批量新增栋阁名称中间只能为正整数或字母！");
                        document.getElementById("iName1").focus();
                        return false;
                    }
                }

                var name2 = document.getElementById("iName2").value;
                if (name2 == "") {
                    alert("批量新增栋阁名称中间不能为空！");
                    document.getElementById("iName2").focus();
                    return false;
                } else {
                if (!LexunJS.isValidPositiveInteger(name2) && !reg.test(name1)) {
                    alert("批量新增栋阁名称中间只能为正整数或字母！");
                        document.getElementById("iName2").focus();
                        return false;
                    }
                }
            }

            var floorTotal = document.getElementById("iFloorTotal").value;
            if (floorTotal == "") {
                alert("总层数不能为空！");
                document.getElementById("iFloorTotal").focus();
                return false;
            } else {
                if (!LexunJS.isValidPositiveInteger(floorTotal)) {
                    alert("总层数只能为正整数！");
                    document.getElementById("iFloorTotal").focus();
                    return false;
                }
            }

            document.forms[0].submit();            
        }
        
    </script>

</body>
</html>
